package com.lyy.common;

import io.minio.MinioClient;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils;

/**
 * @author liushiwei
 */
@Configuration
@Data
@Slf4j
public class LyyMinioAutoConfiguration {

    @Autowired
    LyyMinioProperties properties;

    @Bean
    public MinioClient getMinioClient() {
        log.info("--------启动minio配置--------");
        if(!StringUtils.isEmpty(properties.getEndpoint())) {
            MinioClient minioClient = MinioClient.builder().endpoint(properties.getEndpoint())
                    .credentials(properties.getAccessKey(), properties.getSecretKey()).build();
            MinioUtil.init(minioClient, properties.getBucketName());
            MinioUtil.makeBucket();
            return minioClient;
        }
        return null;
    }

}

